using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace HandWriter
{
	public partial class ActionCountdownDialog : Form
	{
		public delegate void TimerAction();

		private TimerAction _action;
		private int _time;

		public ActionCountdownDialog(int interval, TimerAction action)
		{
			InitializeComponent();
			_action = action;
			_time = interval;
			label1.Text = _time.ToString();
			timer1.Enabled = true;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			if (timer1.Enabled)
			{
				timer1.Enabled = false;
			}
			Close();
		}

		private void timer1_Tick(object sender, EventArgs e)
		{
			if (timer1.Enabled)
			{
				_time--;
				if (_time < 0)
				{
					timer1.Enabled = false;
					Close();
					_action();
				}
			}
			label1.Text = _time.ToString();
		}
	}
}